
pipeline {
    agent {
        node {
            label "label-master"
        }
    }

    options {
        timestamps()                    // 在日志中打印时间
        timeout(time:1, unit:'HOURS')   // 流水线超时设置为1H
        // retry(2)                        // 失败重试2次
    }

    parameters {
        choice (name: 'EnvType', choices: ['dev20'], description: '发布的环境')
        extendedChoice ( 
            defaultValue: '', 
            description: '发布的项目，可多选。注意：配置相关的文件需要自己手动修改', 
            multiSelectDelimiter: ';', 
            name: 'ProjectNames', 
            quoteValue: false, 
            saveJSONParameterToFile: false, 
            type: 'PT_MULTI_SELECT', 
            value:'trunklpg,SaaSAPPlpg,DccAdmin,NewWXShoplpg,09API_WebAPI,09API_WebAPI_LPG', 
            visibleItemCount: 7
        )        
        gitParameter (
            name: 'Branch', 
            type: 'PT_BRANCH',
            defaultValue: 'develop', 
            branchFilter: 'origin/(.*)',
            sortMode: 'ASCENDING_SMART'
        )
    }

    stages {
        stage('Checkout') { 
            steps {
                wrap([$class: 'BuildUser']) {
                    buildName "${BUILD_NUMBER}-${env.BUILD_USER}-${EnvType}-${Branch}"
                }

                dir("C:\\GasErpwyy2021") {
                    script {
                        println "Checkout" 
                        checkout scmGit(
                            branches: [[name: 'refs/heads/' + Branch]],
                            extensions: [], 
                            userRemoteConfigs: [[
                                credentialsId: 'lufei.git', 
                                url: 'http://192.168.2.180:8808/r/GasErpwyy2021.git'
                            ]]
                        )
                    }
                }
            }
        }
    }

    post {
        success {
			println 'build successed'
            build job: '02.GasErpwyy2021.Publish', parameters: [
                string(name: 'EnvType', value: "${EnvType}"), 
                string(name: 'Branch', value: "${Branch}"), 
                string(name: 'ProjectNames', value: "${ProjectNames}")
            ]
        }
        failure {
			println 'build failed'
        }
    }
}
